#include "hw5.h"

/*在做第12题时，该函数已经写进了头文件，这里直接调用即可*/



/*****主函数*****/
int main()
{
    t0 = NULL;
    t1 = (btree)malloc(sizeof(btnode));
    t2 = (btree)malloc(sizeof(btnode));
    t3 = (btree)malloc(sizeof(btnode));
    t4 = (btree)malloc(sizeof(btnode));
    t5 = (btree)malloc(sizeof(btnode));
    t6 = (btree)malloc(sizeof(btnode));
    t7 = (btree)malloc(sizeof(btnode));
    t8 = (btree)malloc(sizeof(btnode));
    t9 = (btree)malloc(sizeof(btnode));

    /***空二叉树***/
    printf("*****空二叉树*****\n");
    t_init();
    print_t(t0);
    if (IsBST(t0) == true)
    {
        printf("\n是BST！\n");
    }
    else
    {
        printf("\n不是BST！\n");
    }
    printf("*****空二叉树*****\n\n\n\n");
    /***空二叉树***/

    /***第1棵非空二叉树***/
    printf("/*****第1棵非空二叉树*****/\n");
    t_init();
    t1->lc = t2;
    t1->rc = t3;
    t2->lc = t4;
    t2->rc = t5;
    t3->lc = t6;
    t3->rc = t7;
    print_t(t1);
    if (IsBST(t1) == true)
    {
        printf("\n是BST！\n");
    }
    else
    {
        printf("\n不是BST！\n");
    }
    printf("/*****第1棵非空二叉树*****/\n\n\n\n");
    /***第1棵非空二叉树***/

    /***第2棵非空二叉树***/
    printf("/*****第2棵非空二叉树*****/\n");
    t_init();
    t5->lc = t3;
    t3->lc = t2;
    t5->rc = t7;
    t7->lc = t6;
    t7->rc = t9;
    t9->lc = t8;
    print_t(t5);
    if (IsBST(t5) == true)
    {
        printf("\n是BST！\n");
    }
    else
    {
        printf("\n不是BST！\n");
    }
    printf("/*****第2棵非空二叉树*****/\n\n\n\n");
    /***第2棵非空二叉树***/

    /***第3棵非空二叉树***/
    printf("/*****第3棵非空二叉树*****/\n");
    t_init();
    t5->lc = t3;
    t3->lc = t2;
    t3->rc = t4;
    t2->lc = t1;
    t5->rc = t7;
    t7->lc = t6;
    t7->rc = t9;
    t9->lc = t8;
    print_t(t5);
    if (IsBST(t5) == true)
    {
        printf("\n是BST！\n");
    }
    else
    {
        printf("\n不是BST！\n");
    }
    printf("/*****第3棵非空二叉树*****/\n\n\n\n");
    /***第3棵非空二叉树***/

    /***第4棵非空二叉树***/
    printf("/*****第4棵非空二叉树*****/\n");
    t_init();
    t5->lc = t3;
    t3->lc = t2;
    t3->rc = t4;
    t2->rc = t1;
    t5->rc = t7;
    t7->lc = t6;
    t7->rc = t9;
    t9->lc = t8;
    print_t(t5);
    if (IsBST(t5) == true)
    {
        printf("\n是BST！\n");
    }
    else
    {
        printf("\n不是BST！\n");
    }
    printf("/*****第4棵非空二叉树*****/\n\n\n\n");
    /***第4棵非空二叉树***/

    system("pause");
}
/*****主函数*****/